﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using Infrastructure.CrossCutting.IoC.InstanceProviders;
using Infrastructure.Mvc.SeedWork.Resources;

namespace Infrastructure.Mvc.SeedWork.ControllerFactory
{
    public class UnityControllerFactory : DefaultControllerFactory
    {
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            if (controllerType == null)
                throw new Exception(Messages.MvcBase_NotFoundPage);
            if (!IocContainer.HasRegistered(controllerType.FullName))
                return base.GetControllerInstance(requestContext, controllerType);
            return (IController) IocContainer.Resolve(controllerType);
        }
    }
}